#!/bin/bash
ABI=$(getprop ro.product.cpu.abi)
GIT_MIRROR="https://gitee.com/kmou424/wfhelperpy_pyin/"
GIT_RAW=$GIT_MIRROR"/raw/main"
PYTHON_BIN="null"

if [[ $ABI =~ "arm64-" ]];then
  PYTHON_BIN="python_3.7.4-1_aarch64_bin.tar.xz"
fi

if [[ $ABI =~ "arm-" ]];then
  PYTHON_BIN="python_3.7.4-1_arm_bin.tar.xz"
fi

if [[ $PYTHON_BIN == "null" ]];then
  echo "Unsupported ABI!"
  exit
fi

echo ""
echo "Installing requirements"
apt-get update
apt-get -y install build-essentials curl git libffi libssh2 openssh openssl wget
echo ""
echo "Get bin files of python"
git clone $GIT_MIRROR pyin_temp && cd pyin_temp && tar -xvf $PYTHON_BIN && rm $PYTHON_BIN
echo ""
echo "Install python..."
cp -R * $PREFIX/
echo ""
echo "Set dynamic library path"
echo "export LD_LIBRARY_PATH=$PREFIX/lib" > ~/.bashrc
export LD_LIBRARY_PATH=$PREFIX/lib:$PREFIX:lib/openssl-1.1
echo ""
echo "Install pip..."
curl https://bootstrap.pypa.io/get-pip.py | python
echo ""
echo "Cleaning up"
cd .. && rm -rf pyin_temp

echo ""
echo "########"
echo "# DONE #"
echo "########"
